//===============================================================================
// Microsoft patterns & practices
// Guidance Explorer Offline Client
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

using System;
using System.Collections.Generic;

namespace GuidanceExplorer.Model
{
    class AndSearchCriteria : Criteria
    {
        private Criteria[] _criteria;

        public AndSearchCriteria(List<Criteria> criteria)
        {
            if (criteria == null && criteria.Count == 0)
                throw new ArgumentNullException("criteria");
            _criteria = criteria.ToArray();
        }

        public Criteria[] Criterias
        {
            get { return _criteria; }
        }

        public override bool Evaluate(GuidanceItem item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            if (_criteria != null)
            {
                bool returnValue = true;
                for (int idx = 0; idx < _criteria.Length; idx++)
                {
                    returnValue &= _criteria[idx].Evaluate(item);
                    if (!returnValue)
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}
